<?php
/**
 * Created by Engineer CuiLiwu.
 * Project: deal.
 * Date: 2018/6/28-10:24
 * License Hangzhou orce Technology Co., Ltd. Copyright © 2018
 */

namespace App\Http\Controllers\Web;

use App\ConstDir\ErrorConst;
use App\Repository\Models\ArticleCategory;
use App\Repository\Repositories\Interfaces\SysArticleRepository;
use App\Repository\Repositories\Interfaces\ArticleCategoryRepository;
use Illuminate\Http\Request;

/**
 * 前台帮助中心，系统文章获取。 
 * */
class HelperController extends BaseController
{
    /**
     * @var SysArticleRepository
     */
    protected $article;
    protected $request;
    protected $article_cate;

    public function __construct(SysArticleRepository $article,ArticleCategoryRepository $article_cate,Request $request)
    {
        parent::__construct();
        $this->request = $request;
        $this->article = $article;
        $this->article_cate = $article_cate;
    }

    /**
     * 获取分类下 文章列表
     * */
    public function index(){
        $list = $this->article->paginate(15);
        return $this->success(ErrorConst::SUCCESS_CODE_MSG, $list, true);
    }

    /**
     * 获取文章详情
     * */
    public function show($id){
        $new_info = $this->article->find($id);
        $up_new   =  $this->article->upDownNewList($id);
        $data = $new_info['data'];
        $data['updown'] = $up_new;
        return $this->success(ErrorConst::SUCCESS_CODE_MSG, $data, true);
    }
    /**
     * 获取分类信息 / 获取当前分类的同级分类
     * */
    public function getCateInfo($id){
        $return = [];
        // 当前分类信息
        $cate_info = $this->article_cate->find($id);
        $return = $cate_info['data'];

        $cate = $this->article_cate->getSysCateList(24); // 获取系统文章 下的所有分类
        $return['all'] = $cate;
//        if (isset($cate_info['data']['fid'])) {
//            $cateSame = ArticleCategory::query()->where(['fid' => $cate_info['data']['fid']])->orderBy('sort','asc')->get()->toArray();
//            $return['cateSame'] = $cateSame;
//        }
        return $this->success(ErrorConst::SUCCESS_CODE_MSG, $return);
    }
}
